package com.anhry.app.safety.manage.zczb.struts.action;

import java.io.File;
import java.util.Date;
import java.util.List;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.anhry.app.safety.manage.system.bean.TbUser;
import com.anhry.app.safety.manage.system.bean.TbUserDept;
import com.anhry.app.safety.manage.zczb.bean.TbZczbBgd;
import com.anhry.app.safety.manage.zczb.bean.TbZczbBzhType;
import com.anhry.app.safety.manage.zczb.bean.TbZczbHzd;
import com.anhry.app.safety.manage.zczb.bean.TbZczbYh;
import com.anhry.app.safety.manage.zczb.bean.TbZczbYhFj;
import com.anhry.app.safety.manage.zczb.struts.base.ZczbBaseAction;
import com.anhry.app.safety.util.DateFormater;
import com.anhry.app.safety.util.Loggers;
import com.anhry.app.safety.util.Page;
import com.anhry.app.safety.util.UploadFile;
import com.anhry.app.safety.util.Util;
import com.anhry.app.safety.util.UtilMethod;

/**
 * @date:2012-10-28
 * @remark:重大隐患管理
 * @author:dongbin
 */
@Controller
@Scope("prototype")
@SuppressWarnings("unchecked")
public class BigYhAction extends ZczbBaseAction{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private String cAudit;
	private String cGp;
	private String cZg;
	private String cBtime;
	private String cEtime;
	private String auditType;//
	private String auditMsg;//备注信息
	private String yhStatus;
	private String yhGpType;
	private String yhGpDate;
	private String yhXhDate;
	private String yhGpCode;//挂牌督办文号
	private String yhGpUnit;//挂牌督办单位
	private String yhZgUnit;//整改单位
	private String yhZrUnit;//责任单位
	private String yhZgPer;//整改责任人（单位的）
	private String yhZgZj;//整改资金 单位元
	private String yhDw1;//整改责任是否到位 0：否1：是
	private String yhDw2;//整改措施是否到位 
	private String yhDw3;//整改资金是否到位
	private String yhDw4;//整改时限是否到位
	private String yhDw5;//应急预案是否到位
	private String yhDwDate1;//到位日期
	private String yhDwDate2;//
	private String yhDwDate3;//
	private String yhDwDate4;//
	private String yhDwDate5;//
	private String isSubmit;//
	private String yhWcDate;//
	private String yhType;//
	private String corpId;
	private List yhTypeList;
	private List corpList;
	private String yhJkcs;//监控及治理措施
	private String yhYxfw;//影响范围及危害后果
	private String yhXcyy;//隐患形成详细原因
	private String yhAdds;//隐患地点
	private String yhBwei;//隐患部位
	private String yhFxTime;//发现隐患时间
	private String yhZgType;//隐患整改类型1：立即整改2：限期整改3：停业停产整顿
	private String yhZgZrr;//整改责任人
	private String yhZrrTel;//整改责任人电话
	private String yhZgTime;//整改期限
	
	/**
	 * 重大隐患管理
	 * @return
	 */
	public String corpYhList(){
		int rowCount = 0;
		int num = (this.num != null && !"".equals(this.num ))?Integer.parseInt(this.num ):1;
		int size = (this.size != null && !"".equals(this.size ))?Integer.parseInt(this.size ):10;
		if(null!=this.getSearch() && "1".equals(this.getSearch())){num = 1;size = 10;}
		try {
			TbUser user = (TbUser)this.contextPvd.getSessionAttr(Util.SESSION_ADMINUSER);
			String orderHql = " order by t.yhFxTime desc";//排序hql语句
			String hql = this.getQuaryHql(1,1);
			List objSize = this.utilService.getObjecList("TbZczbBigYhView", hql,null,0,0);
			if(objSize != null && objSize.size() > 0){
				rowCount = Integer.parseInt(objSize.get(0).toString());
			}
			Page page = new Page(size,num,rowCount);
			this.setPage(page);
			this.setObjList(this.utilService.getObjecList("TbZczbBigYhView", hql,orderHql,page.getStartRow(),page.getSize()));
			this.setSdList(this.enterprisService.getSdList((List)this.contextPvd.getServletContextAttr(Util.QU_DEPT_LIST),user));
			this.setTypeList(this.enterprisService.getTypeList(user));
			this.setHyList((List)this.contextPvd.getServletContextAttr(Util.HY_DEPT_LIST));
			this.setResult("big_corp_list");
			return SUCCESS;
		} catch (Exception e) {
			e.printStackTrace();
			Loggers.info("zczb BigYhAction corpYhList()异常："+e.getMessage());
		}
		return ERROR;
	}
	
	/**
	 * 跳转到操作页面
	 * @return
	 */
	public String corpYhAudit(){
		try {
			if(null!=this.yhId && this.yhId.length()>0){
				TbZczbYh yh = (TbZczbYh)this.utilService.getObjectById(TbZczbYh.class, Long.parseLong(this.yhId));
				if(null!=yh){
					this.setYh(yh);
					if(null!=this.auditType && this.auditType.length()>0){
						switch (Integer.parseInt(this.auditType)) {
						case 1:this.setResult("big_corp_audit");break;//企业上报审核
						case 2:this.setResult("big_gp");break;
						case 3:
							this.setFjList1(this.zczbService.getYhFjList("4", this.yhId));
							this.setResult("big_zg");break;
						case 4:
							this.setResult("big_xh");break;
						case 5:this.setResult("big_audit");break;//管理人员上报审核
						case 6:this.setResult("big_back");break;//打回理由
						default:
							return ERROR;
						}
						return SUCCESS;
					}
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
			Loggers.info("zczb BigYhAction corpYhAudit()异常："+e.getMessage());
		}
		return ERROR;
	}
	/**
	 * 跳转到操作页面
	 * @return
	 */
	public String yhZgShow(){
		try {
			if(null!=this.yhId && this.yhId.length()>0){
				TbZczbYh yh = (TbZczbYh)this.utilService.getObjectById(TbZczbYh.class, Long.parseLong(this.yhId));
				if(null!=yh){
					this.setYh(yh);
					this.setFjList1(this.zczbService.getYhFjList("4", this.yhId));
					this.setResult("big_zg_show");
					return SUCCESS;
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
			Loggers.info("zczb BigYhAction corpYhAudit()异常："+e.getMessage());
		}
		return ERROR;
	}
	/**
	 * 企业上报审核结果保存
	 * @return
	 */
	public String corpYhAuditSave(){
		try {
			if(null!=this.yhId && this.yhId.length()>0){
				TbZczbYh yh = (TbZczbYh)this.utilService.getObjectById(TbZczbYh.class, Long.parseLong(this.yhId));
				if(null!=yh){
					if("95".equals(this.yhStatus)){//隐患打回
						yh.setYhType("1");
						yh.setYhStatus(Integer.parseInt(this.yhStatus));
						yh.setYhBack(this.auditMsg);
					}else if("2".equals(this.yhStatus)){//上报县区安委会
						yh.setYhStatus(Integer.parseInt(this.yhStatus));
						yh.setYhAuditMsg1(this.auditMsg);
						yh.setYhAuditDate1(new Date());
					}else if("3".equals(this.yhStatus)){//上报市安委会
						yh.setYhStatus(Integer.parseInt(this.yhStatus));
						yh.setYhAuditMsg2(this.auditMsg);
						yh.setYhAuditDate2(new Date());
					}else{//审核通过
						yh.setYhAudit(yh.getYhStatus()+"");//是哪级用户确认的 1：属地2：县(市、区)、开发区安委会3：市安委会
						yh.setYhStatus(Integer.parseInt(this.yhStatus));
					}
					this.utilService.update(yh);
					if("95".equals(this.yhStatus)){//隐患打回
						if(null!=yh.getBgdId()){
							TbZczbBgd bgd = (TbZczbBgd)this.utilService.getObjectById(TbZczbBgd.class, yh.getBgdId());
							if(null!=bgd){
								bgd.setBgdBigNum(bgd.getBgdBigNum()-1);
								bgd.setBgdSameNum(bgd.getBgdSameNum()+1);
								this.utilService.update(bgd);
								if(null!=bgd.getHzdId()){
									TbZczbHzd hzd = (TbZczbHzd)this.utilService.getObjectById(TbZczbHzd.class, bgd.getHzdId());
									hzd.setHzdBigNum(hzd.getHzdBigNum()-1);
									hzd.setHzdSameNum(hzd.getHzdSameNum()+1);
									hzd.setHzdStatus("2");
									hzd.setHzdBackLy(this.auditMsg);
									this.utilService.update(hzd);
								}
							}
						}
					}
					this.setTip("操作成功！");
					return this.corpYhAudit();
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
			Loggers.info("zczb BigYhAction corpYhAuditSave()异常："+e.getMessage());
		}
		return ERROR;
	}
	
	/**
	 * 管理部门审核结果保存
	 * @return
	 */
	public String yhAuditSave(){
		try {
			if(null!=this.yhId && this.yhId.length()>0){
				TbZczbYh yh = (TbZczbYh)this.utilService.getObjectById(TbZczbYh.class, Long.parseLong(this.yhId));
				if(null!=yh){
					if("95".equals(this.yhStatus)){//隐患打回
						yh.setYhStatus(Integer.parseInt(this.yhStatus));
						yh.setYhBack(this.auditMsg);
						yh.setYhAudit(String.valueOf((yh.getYhStatus()+1)).trim());//是哪级用户确认的2：县(市、区)、开发区安委会3：市安委会
					}else if("2".equals(this.yhStatus)){//上报市安委会
						yh.setYhStatus(Integer.parseInt(this.yhStatus));
						yh.setYhAuditMsg1(this.auditMsg);
						yh.setYhAuditDate1(new Date());
					}else{//审核通过
						yh.setYhAudit(String.valueOf((yh.getYhStatus()+1)).trim());//是哪级用户确认的2：县(市、区)、开发区安委会3：市安委会
						yh.setYhStatus(Integer.parseInt(this.yhStatus));
					}
					this.utilService.update(yh);
					this.setTip("操作成功！");
					return this.corpYhAudit();
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
			Loggers.info("zczb BigYhAction yhAuditSave()异常："+e.getMessage());
		}
		return ERROR;
	}
	/**
	 * 挂牌保存
	 * @return
	 */
	public String yhGpSave(){
		try {
			if(null!=this.yhId && this.yhId.length()>0){
				TbZczbYh yh = (TbZczbYh)this.utilService.getObjectById(TbZczbYh.class, Long.parseLong(this.yhId));
				if(null!=yh){
					yh.setYhIsGp("1");
					if("1".equals(yh.getYhAudit())){//属地确认
						yh.setYhGpType("5");
					}
					if("2".equals(yh.getYhAudit())){//县区安委会确认 
						yh.setYhGpType("4");
					}
					if("3".equals(yh.getYhAudit())){//市安委会确认
						yh.setYhGpType(yhGpType);
					}
					if(null!=this.yhGpDate && this.yhGpDate.length()>0){
						yh.setYhGpDate(DateFormater.formatDate(this.yhGpDate));
					}else{
						yh.setYhGpDate(new Date());
					}
					yh.setYhStatus(97);
					yh.setYhGpCode(yhGpCode);
					yh.setYhGpUnit(yhGpUnit);
					this.utilService.update(yh);
					this.setTip("操作成功！");
					return this.corpYhAudit();
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
			Loggers.info("zczb BigYhAction yhGpSave()异常："+e.getMessage());
		}
		return ERROR;
	}
	/**
	 * 申请销号
	 * @return
	 */
	public String yhSqXh(){
		try {
			if(null!=this.yhId && this.yhId.length()>0){
				TbZczbYh yh = (TbZczbYh)this.utilService.getObjectById(TbZczbYh.class, Long.parseLong(this.yhId));
				if(null!=yh){
					yh.setYhStatus(98);
					yh.setYhSqXh("1");
					this.utilService.update(yh);
					this.setTip("操作成功！");
					if("1".equals(yh.getYhCome())){
						return this.corpYhList();
					}
					return this.yhList();
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
			Loggers.info("zczb BigYhAction yhSqXh()异常："+e.getMessage());
		}
		return ERROR;
	}
	/**
	 * 销号
	 * @return
	 */
	public String yhXhSave(){
		try {
			if(null!=this.yhId && this.yhId.length()>0){
				TbZczbYh yh = (TbZczbYh)this.utilService.getObjectById(TbZczbYh.class, Long.parseLong(this.yhId));
				if(null!=yh){
					yh.setYhIsXh("1");
					yh.setYhStatus(99);
					if(null!=this.yhXhDate && this.yhXhDate.length()>0){
						yh.setYhXhDate(DateFormater.formatDate(this.yhXhDate));
					}else{
						yh.setYhXhDate(new Date());
					}
					this.utilService.update(yh);
					this.setTip("操作成功！");
					return this.corpYhAudit();
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
			Loggers.info("zczb BigYhAction yhGpSave()异常："+e.getMessage());
		}
		return ERROR;
	}
	
	/**
	 * 整改信息保存
	 * @return
	 */
	public String yhZgSave(){
		try {
			if(null!=this.yhId && this.yhId.length()>0){
				TbZczbYh yh = (TbZczbYh)this.utilService.getObjectById(TbZczbYh.class, Long.parseLong(this.yhId));
				if(null!=yh){
					yh.setYhZgUnit(yhZgUnit);
					yh.setYhZrUnit(yhZrUnit);
					yh.setYhZgPer(yhZgPer);
					yh.setYhZgZj(yhZgZj);
					yh.setYhDw1(yhDw1);
					yh.setYhDw2(yhDw2);
					yh.setYhDw3(yhDw3);
					yh.setYhDw4(yhDw4);
					yh.setYhDw5(yhDw5);
					if(null!=this.yhDwDate1 && this.yhDwDate1.length()>0){
						yh.setYhDwDate1(DateFormater.formatDate(this.yhDwDate1));
					}
					if(null!=this.yhDwDate2 && this.yhDwDate2.length()>0){
						yh.setYhDwDate2(DateFormater.formatDate(this.yhDwDate2));
					}
					if(null!=this.yhDwDate3 && this.yhDwDate3.length()>0){
						yh.setYhDwDate3(DateFormater.formatDate(this.yhDwDate3));
					}
					if(null!=this.yhDwDate4 && this.yhDwDate4.length()>0){
						yh.setYhDwDate4(DateFormater.formatDate(this.yhDwDate4));
					}
					if(null!=this.yhDwDate5 && this.yhDwDate5.length()>0){
						yh.setYhDwDate5(DateFormater.formatDate(this.yhDwDate5));
					}
					if(null!=this.yhZgTime && this.yhZgTime.length()>0){
						yh.setYhZgTime(DateFormater.formatDate(this.yhZgTime));
					}
					if("2".equals(this.isSubmit)){
						yh.setYhIsZg("1");
						if(null!=this.yhWcDate && this.yhWcDate.length()>0){
							yh.setYhWcTime(DateFormater.formatDate(this.yhWcDate));
						}
						if(null!=yh.getBgdId()){
							TbZczbBgd bgd = (TbZczbBgd)this.utilService.getObjectById(TbZczbBgd.class, yh.getBgdId());
							if(null!=bgd){
								bgd.setBgdBigCl(bgd.getBgdBigCl()+1);
								bgd.setBgdWclNum(bgd.getBgdWclNum()-1);
								this.utilService.update(bgd);
								if(null!=bgd.getHzdId()){
									TbZczbHzd hzd = (TbZczbHzd)this.utilService.getObjectById(TbZczbHzd.class, bgd.getHzdId());
									hzd.setHzdBigCl(hzd.getHzdBigCl()+1);
									hzd.setHzdWclNum(hzd.getHzdWclNum()-1);
									this.utilService.update(hzd);
								}
							}
						}
					}
					this.utilService.update(yh);
					if(null!=this.docFile && this.docFile.length>0){
						for(int i=0;i<this.docFile.length;i++){
							TbZczbYhFj fj = new TbZczbYhFj();
							fj.setFjTitle(this.docFileFileName[i]);
							String tem_path = Util.SAFETY_FILE+File.separator+Util.FILE_FOLDER+File.separator+Util.ZCZB;
							String fileName = UploadFile.copy2(this.docFile[i], tem_path, this.docFileFileName[i]);
							String path = Util.FILE_FOLDER+File.separator+Util.ZCZB+File.separator+fileName;
							fj.setFjPath(path);
							fj.setIsDele("0");
							fj.setFjType("4");
							fj.setYhId(yh.getId());
							this.utilService.save(fj);
						}
					}
					this.setTip("操作成功！");
					return this.corpYhAudit();
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
			Loggers.info("zczb BigYhAction yhZgSave()异常："+e.getMessage());
		}
		return ERROR;
	}
	
	/**
	 * 异步删除附件
	 *
	 */
	public void deleFj(){
		this.contextPvd.getResponse().setContentType("charset=UTF-8");
		try {
			if(null!=this.getFjId() && !"".equals(this.getFjId())){
				TbZczbYhFj fj = (TbZczbYhFj)this.utilService.getObjectById(TbZczbYhFj.class, Long.parseLong(this.fjId));
				if(null!=fj){
					UploadFile.removeFile(Util.SAFETY_FILE + File.separator + fj.getFjPath());
					this.utilService.delete(fj);
				}
				this.contextPvd.getResponse().getWriter().write("1");
			}else{
				this.contextPvd.getResponse().getWriter().write("2");
			}
			this.contextPvd.getResponse().getWriter().flush();
			this.contextPvd.getResponse().getWriter().close();
		} catch (Exception e) {
			e.printStackTrace();
			Loggers.info("zczb BigYhAction deleFj()异常："+e.getMessage());
		}
	}
	
	/**
	 * 管理部门上报隐患
	 * @return
	 */
	public String yhList(){
		int rowCount = 0;
		int num = (this.num != null && !"".equals(this.num ))?Integer.parseInt(this.num ):1;
		int size = (this.size != null && !"".equals(this.size ))?Integer.parseInt(this.size ):10;
		if(null!=this.getSearch() && "1".equals(this.getSearch())){num = 1;size = 10;}
		try {
			TbUser user = (TbUser)this.contextPvd.getSessionAttr(Util.SESSION_ADMINUSER);
			String orderHql = " order by t.yhFxTime desc";//排序hql语句
			String hql = this.getQuaryHql(1,2);
			List objSize = this.utilService.getObjecList("TbZczbBigYhView", hql,null,0,0);
			if(objSize != null && objSize.size() > 0){
				rowCount = Integer.parseInt(objSize.get(0).toString());
			}
			Page page = new Page(size,num,rowCount);
			this.setPage(page);
			this.setObjList(this.utilService.getObjecList("TbZczbBigYhView", hql,orderHql,page.getStartRow(),page.getSize()));
			this.setSdList(this.enterprisService.getSdList((List)this.contextPvd.getServletContextAttr(Util.QU_DEPT_LIST),user));
			this.setTypeList(this.enterprisService.getTypeList(user));
			this.setHyList((List)this.contextPvd.getServletContextAttr(Util.HY_DEPT_LIST));
			this.setResult("big_list");
			return SUCCESS;
		} catch (Exception e) {
			e.printStackTrace();
			Loggers.info("zczb BigYhAction yhList()异常："+e.getMessage());
		}
		return ERROR;
	}
	
	/**
	 * 重大隐患上报
	 * @return
	 */
	public String yhAdd(){
		try {
			if(null!=this.yhId && this.yhId.length()>0){
				TbZczbYh yh = (TbZczbYh)this.utilService.getObjectById(TbZczbYh.class, Long.parseLong(this.yhId));
				if(null!=yh){
					this.setYh(yh);
				}
			}
			this.setYhTypeList((List)this.utilService.getHqlQuery("from TbZczbBzhType t where 1=1 and t.typeParentId<>0 order by t.id"));
			this.setResult("big_add");
			return SUCCESS;
		} catch (Exception e) {
			e.printStackTrace();
			Loggers.info("zczb BigYhAction yhList()异常："+e.getMessage());
		}
		return ERROR;
	}
	
	/**
	 * 重大隐患保存
	 * @return
	 */
	public String yhSave(){
		try {
			TbUser user = (TbUser)this.contextPvd.getSessionAttr(Util.SESSION_ADMINUSER);
			String grade = user.getTbUserGrade().getId().toString();//用户级别
			if(null!=this.yhId && this.yhId.length()>0){
				TbZczbYh yh = (TbZczbYh)this.utilService.getObjectById(TbZczbYh.class, this.yhId);
				yh = this.initYh(yh);
				this.utilService.update(yh);
				return this.saveYhfj(yh);
			}else{
				TbZczbYh yh = new TbZczbYh();
				yh = this.initYh(yh);
				yh.setCorpId(Long.parseLong(corpId));
				yh.setYhDate(new Date());
				if("7".equals(grade)){//属地
					yh.setYhCome("2");
					yh.setYhStatus(1);
				}else if("6".equals(grade) || "4".equals(grade)){//区行业
					yh.setYhCome("3");
					yh.setYhStatus(1);
				}else if("3".equals(grade) || "5".equals(grade)){//市行业
					yh.setYhCome("4");
					yh.setYhStatus(2);
				}
				if(null!=user.getTbUserUnit()){
					yh.setYhUnitId(user.getTbUserUnit().getId());
					yh.setYhUnitName(user.getTbUserUnit().getDeptName());
				}
				if(null!=user.getTbUserDept()){
					yh.setYhDeptId(user.getTbUserDept().getId());
					yh.setYhDeptName(user.getTbUserDept().getDeptName());
				}
				this.utilService.save(yh);
				return this.saveYhfj(yh);
			}
		} catch (Exception e) {
			e.printStackTrace();
			Loggers.info("zczb BigYhAction yhSave()异常："+e.getMessage());
		}
		return ERROR;
	}
	
	/**
	 * 初始化隐患信息
	 * @param yh
	 * @return
	 */
	public TbZczbYh initYh(TbZczbYh yh){
		try {
			if(null!=this.yhFxTime && this.yhFxTime.length()>0){
				yh.setYhFxTime(DateFormater.formatDate(yhFxTime));
			}
			if(null!=this.yhType && this.yhType.length()>0){
				TbZczbBzhType type = (TbZczbBzhType)this.utilService.getObjectById(TbZczbBzhType.class, Long.parseLong(yhType));
				if(null!=type){
					yh.setYhType1(type.getTypeParentId());
					yh.setYhType1Name(type.getTypeParentName());
					yh.setYhType2(type.getId());
					yh.setYhType2Name(type.getTypeName());
				}
			}
			yh.setYhIsGp("0");
			yh.setYhIsXh("0");
			yh.setYhJkcs(yhJkcs);
			yh.setYhType("2");
			yh.setYhXcyy(yhXcyy);
			yh.setYhYxfw(yhYxfw);
			yh.setYhZgZrr(yhZgZrr);
			yh.setYhZrrTel(yhZrrTel);
			yh.setYhIsZg("0");
			yh.setYhZgType(yhZgType);
			yh.setYhAdds(yhAdds);
			yh.setYhBwei(yhBwei);
		} catch (Exception e) {
			e.printStackTrace();
			Loggers.info("zczb TbZczbYh initYh(TbZczbYh yh)异常："+e.getMessage());
		}
		return yh;
	}
	
	/**
	 * 隐患附件保存
	 * @param yh
	 */
	public String saveYhfj(TbZczbYh yh){
		try {
			if(null!=this.fjFile && this.fjFile.length>0){
				for(int i=0;i<this.fjFile.length;i++){
					if(!UtilMethod.filterType(this.fjFileContentType[i], Util.ALLOWTYPES.split(","))){
						this.setTip("图片附件格式错误,请重新上传！");
						return this.yhAdd();
					}
				}
				for(int i=0;i<this.fjFile.length;i++){
					TbZczbYhFj fj = new TbZczbYhFj();
					fj.setFjTitle(this.fjFileFileName[i]);
					String tem_path = Util.SAFETY_FILE+File.separator+Util.FILE_FOLDER+File.separator+Util.ZCZB;
					String fileName = UploadFile.copy2(this.fjFile[i], tem_path, this.fjFileFileName[i]);
					String path = Util.FILE_FOLDER+File.separator+Util.ZCZB+File.separator+fileName;
					fj.setFjPath(path);
					fj.setIsDele("0");
					fj.setFjType("1");
					fj.setYhId(yh.getId());
					this.utilService.save(fj);
				}
			}
			if(null!=this.docFile && this.docFile.length>0){
				for(int i=0;i<this.docFile.length;i++){
					TbZczbYhFj fj = new TbZczbYhFj();
					fj.setFjTitle(this.docFileFileName[i]);
					String tem_path = Util.SAFETY_FILE+File.separator+Util.FILE_FOLDER+File.separator+Util.ZCZB;
					String fileName = UploadFile.copy2(this.docFile[i], tem_path, this.docFileFileName[i]);
					String path = Util.FILE_FOLDER+File.separator+Util.ZCZB+File.separator+fileName;
					fj.setFjPath(path);
					fj.setIsDele("0");
					fj.setFjType("3");
					fj.setYhId(yh.getId());
					this.utilService.save(fj);
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
			Loggers.info("zczb String saveYhfj(TbZczbYh yh)异常："+e.getMessage());
		}
		this.setTip("操作成功！");
		return this.yhList();
	}
	
	/**
	 * 隐患详细信息
	 * @return
	 */
	public String yhShow(){
		try {
			if(null!=this.yhId && this.yhId.length()>0){
				TbZczbYh yh = (TbZczbYh)this.utilService.getObjectById(TbZczbYh.class, Long.parseLong(this.yhId));
				if(null!=yh){
					this.setYh(yh);
					this.setFjList1(this.zczbService.getYhFjList("1",this.yhId));
					this.setFjList2(this.zczbService.getYhFjList("2",this.yhId));
					this.setFjList3(this.zczbService.getYhFjList("3",this.yhId));
					this.setResult("big_show");
					return SUCCESS;
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
			Loggers.error("zczbAction yhShow()异常："+e.getMessage());
		}
		return ERROR;
	}
	
	/**
	 * 企业列表
	 * @return
	 */
	public String corpList(){
		int rowCount = 0;
		int num = (this.num != null && !"".equals(this.num ))?Integer.parseInt(this.num ):1;
		int size = (this.size != null && !"".equals(this.size ))?Integer.parseInt(this.size ):10;
		try {
			TbUser user = (TbUser)this.contextPvd.getSessionAttr(Util.SESSION_ADMINUSER);
			String orderHql = " order by t.countyId,t.unitId,t.deptId,t.id";//排序hql语句
			String hql = this.getQuaryHql(0,0);
			List objSize = this.enterprisService.getCorpList(hql,null,0,0);
			if(objSize != null && objSize.size() > 0){
				rowCount = Integer.parseInt(objSize.get(0).toString());
			}
			Page page = new Page(size,num,rowCount);
			this.setPage(page);
			this.setCorpList(this.enterprisService.getCorpList(hql,orderHql,page.getStartRow(),page.getSize()));
			
			this.setSdList(this.enterprisService.getSdList((List)this.contextPvd.getServletContextAttr(Util.QU_DEPT_LIST),user));
			this.setTypeList(this.enterprisService.getTypeList(user));
			this.setHyList((List)this.contextPvd.getServletContextAttr(Util.HY_DEPT_LIST));
			this.setResult("corp_list");
			return SUCCESS;
		} catch (Exception e) {
			e.printStackTrace();
			Loggers.info("zczb BigYhAction corpList()异常："+e.getMessage());
		}
		return ERROR;
	}
	
	public String getQuaryHql(int method,int type){
		TbUser user = (TbUser)this.contextPvd.getSessionAttr(Util.SESSION_ADMINUSER);
		String grade = user.getTbUserGrade().getId().toString();//用户级别
		TbUserDept unit = null;//用户单位
		TbUserDept dept = null;//用户部门
		if(null!=user.getTbUserUnit()){
			unit = user.getTbUserUnit();
		}
		if(null!=user.getTbUserDept()){
			dept = user.getTbUserDept();
		}
		StringBuilder urls = new StringBuilder("");
		StringBuilder hql = new StringBuilder(" where 1=1 ");
		String key = "";
		if(null!=this.keyWord && this.keyWord.length()>0){
			if(null!=this.getSearch() && "1".equals(this.getSearch())){
				key = this.getKeyWord().trim();
			}else{
				key = this.contextPvd.decode(this.getKeyWord());	
			}
			this.setKeyWord(key);
			hql.append(" and t.corpName like '%"+key+"%'");
			urls.append("keyWord="+this.contextPvd.encode(this.keyWord));
		}else{
			urls.append("keyWord=");
		}
		
		if("3".equals(grade) && "3".equals(dept.getDeptClass())){//市科室行业部门
			hql.append(" and t.deptMainId="+dept.getId());
			urls.append("&cHy="+dept.getId().toString());
			this.setCHy(dept.getId().toString());
			if(null!=this.cMaxType && this.cMaxType.length()>0){
				hql.append(" and t.maxTypeId="+this.cMaxType);
				urls.append("&cMaxType="+this.cMaxType);
			}
			if(null!=this.cMinType && this.cMinType.length()>0){
				hql.append(" and t.minTypeId="+this.cMinType);
				urls.append("&cMinType="+this.cMinType);
			}
		}else if("4".equals(grade) && "3".equals(dept.getDeptClass())){//县区科室行业部门
			if((null==this.cMaxType || "".equals(this.cMaxType)) && (null==this.cMinType || "".equals(this.cMinType))){
				hql.append(" and t.quDeptIds like '%"+dept.getId()+"%'");
			}else{
				if(null!=this.cMaxType && this.cMaxType.length()>0){
					hql.append(" and t.maxTypeId="+this.cMaxType);
					urls.append("&cMaxType="+this.cMaxType);
				}
				if(null!=this.cMinType && this.cMinType.length()>0){
					hql.append(" and t.minTypeId="+this.cMinType);
					urls.append("&cMinType="+this.cMinType);
				}
			}
			if(null!=this.cHy && this.cHy.length()>0){
				hql.append(" and t.deptMainId="+this.cHy);
				urls.append("&cHy="+this.cHy);
			}
		}else if("5".equals(grade)){//市行业
			if("1".equals(unit.getDeptClass())){//行业监管
				hql.append(" and t.deptMainId="+unit.getId());
				urls.append("&cHy="+unit.getId().toString());
				this.setCHy(unit.getId().toString());
			}else{//专业监管
				if("5310".equals(unit.getId().toString())){//质监局
					hql.append(" and t.corpIsTeshe=1");
				}else if("5311".equals(unit.getId().toString())){//消防局
					
				}else if("5312".equals(unit.getId().toString())){//气象局
					hql.append(" and t.corpIsBlzh=1");
				}
				if(null!=this.cHy && this.cHy.length()>0){
					hql.append(" and t.deptMainId="+this.cHy);
					urls.append("&cHy="+this.cHy);
				}
			}
			if(null!=this.cMaxType && this.cMaxType.length()>0){
				hql.append(" and t.maxTypeId="+this.cMaxType);
				urls.append("&cMaxType="+this.cMaxType);
			}
			if(null!=this.cMinType && this.cMinType.length()>0){
				hql.append(" and t.minTypeId="+this.cMinType);
				urls.append("&cMinType="+this.cMinType);
			}
		}else if("6".equals(grade)){//区行业
			if("1".equals(dept.getDeptClass())){
				hql.append(" and t.deptMainId="+dept.getDeptSj());
				urls.append("&cHy="+dept.getDeptSj().toString());
				this.setCHy(dept.getDeptSj().toString());
			}else{
				if("5310".equals(dept.getDeptSj().toString())){//质监局
					hql.append(" and t.corpIsTeshe=1");
				}else if("5311".equals(dept.getDeptSj().toString())){//消防局
					
				}else if("5312".equals(dept.getDeptSj().toString())){//气象局
					hql.append(" and t.corpIsBlzh=1");
				}
				if(null!=this.cHy && this.cHy.length()>0){
					hql.append(" and t.deptMainId="+this.cHy);
					urls.append("&cHy="+this.cHy);
				}
			}
			if(null!=this.cMaxType && this.cMaxType.length()>0){
				hql.append(" and t.maxTypeId="+this.cMaxType);
				urls.append("&cMaxType="+this.cMaxType);
			}
			if(null!=this.cMinType && this.cMinType.length()>0){
				hql.append(" and t.minTypeId="+this.cMinType);
				urls.append("&cMinType="+this.cMinType);
			}
		}else{//其他用户
			if(null!=this.cMaxType && this.cMaxType.length()>0){
				hql.append(" and t.maxTypeId="+this.cMaxType);
				urls.append("&cMaxType="+this.cMaxType);
			}
			if(null!=this.cMinType && this.cMinType.length()>0){
				hql.append(" and t.minTypeId="+this.cMinType);
				urls.append("&cMinType="+this.cMinType);
			}
			if(null!=this.cHy && this.cHy.length()>0){
				hql.append(" and t.deptMainId="+this.cHy);
				urls.append("&cHy="+this.cHy);
			}
		}
		
		if("4".equals(grade) || "6".equals(grade) || "8".equals(grade)){//县区安委会、区科室、区行业
			hql.append(" and t.countyId="+unit.getId());
			this.setCCounty(unit.getId().toString());
			if(null!=this.cUnit && this.cUnit.length()>0){
				hql.append(" and t.unitId="+this.cUnit);
				urls.append("&cUnit="+this.cUnit);
			}
			if(null!=this.cDept && this.cDept.length()>0){
				hql.append(" and t.deptId="+this.cDept);
				urls.append("&cDept="+this.cDept);
			}
		}else if("7".equals(grade)){//属地
			hql.append(" and t.countyId="+unit.getId()+" and t.unitId="+dept.getId());
			this.setCCounty(unit.getId().toString());
			this.setCUnit(dept.getId().toString());
			if(null!=this.cDept && this.cDept.length()>0){
				hql.append(" and t.deptId="+this.cDept);
				urls.append("&cDept="+this.cDept);
			}
		}else{
			if(null!=this.cCounty && this.cCounty.length()>0){
				hql.append(" and t.countyId="+this.cCounty);
				urls.append("&cCounty="+this.cCounty);
			}
			if(null!=this.cUnit && this.cUnit.length()>0){
				hql.append(" and t.unitId="+this.cUnit);
				urls.append("&cUnit="+this.cUnit);
			}
			if(null!=this.cDept && this.cDept.length()>0){
				hql.append(" and t.deptId="+this.cDept);
				urls.append("&cDept="+this.cDept);
			}
		}
		if(null!=this.cGrade && this.cGrade.length()>0){
			if("E".equals(this.cGrade)){
				hql.append(" and t.corpGrade is null");
			}else{
				hql.append(" and t.corpGrade='"+this.cGrade+"'");
			}
			urls.append("&cGrade="+this.cGrade);
		}
		
		if(method==1){//隐患查询
			if(null!=this.cAudit && this.cAudit.length()>0){
				hql.append(" and t.yhStatus="+this.cAudit);
				urls.append("&cAudit="+this.cAudit);
			}
			if(null!=this.cGp && this.cGp.length()>0){
				hql.append(" and t.yhGpType="+this.cGp);
				urls.append("&cGp="+this.cGp);
			}
			if(null!=this.cZg && this.cZg.length()>0){
				hql.append(" and t.yhIsZg="+this.cZg);
				urls.append("&cZg="+this.cZg);
			}
			if(null!=this.cBtime && this.cBtime.length()>0 && null!=this.cEtime && this.cEtime.length()>0){
				hql.append(" and to_char(t.yhFxTime,'yyyy-mm-dd') between '"+cBtime+"' and '"+cEtime+"'");
				urls.append("&cBtime="+this.cBtime);
				urls.append("&cEtime="+this.cEtime);
			}
			if(type==1){
				hql.append(" and t.yhCome=1");
			}else{
				if("7".equals(grade)){//属地
					hql.append(" and t.yhCome=2");
				}else if("6".equals(grade) || "4".equals(grade)){//区行业
					hql.append(" and t.yhCome=3");
				}else if("3".equals(grade) || "5".equals(grade)){//市行业
					hql.append(" and (t.yhCome=4 or t.yhCome=3)");
				}else{
					hql.append(" and t.yhCome in(2,3,4)");
				}
			}
		}
		this.setUrls(urls.toString());
		return hql.toString();
	}

	public String getCAudit() {
		return cAudit;
	}

	public void setCAudit(String audit) {
		cAudit = audit;
	}

	public String getCBtime() {
		return cBtime;
	}

	public void setCBtime(String btime) {
		cBtime = btime;
	}

	public String getCEtime() {
		return cEtime;
	}

	public void setCEtime(String etime) {
		cEtime = etime;
	}

	public String getCGp() {
		return cGp;
	}

	public void setCGp(String gp) {
		cGp = gp;
	}

	public String getCZg() {
		return cZg;
	}

	public void setCZg(String zg) {
		cZg = zg;
	}

	public String getAuditType() {
		return auditType;
	}

	public void setAuditType(String auditType) {
		this.auditType = auditType;
	}

	public String getAuditMsg() {
		return auditMsg;
	}

	public void setAuditMsg(String auditMsg) {
		this.auditMsg = auditMsg;
	}

	public String getYhStatus() {
		return yhStatus;
	}

	public void setYhStatus(String yhStatus) {
		this.yhStatus = yhStatus;
	}

	public String getYhDw1() {
		return yhDw1;
	}

	public void setYhDw1(String yhDw1) {
		this.yhDw1 = yhDw1;
	}

	public String getYhDw2() {
		return yhDw2;
	}

	public void setYhDw2(String yhDw2) {
		this.yhDw2 = yhDw2;
	}

	public String getYhDw3() {
		return yhDw3;
	}

	public void setYhDw3(String yhDw3) {
		this.yhDw3 = yhDw3;
	}

	public String getYhDw4() {
		return yhDw4;
	}

	public void setYhDw4(String yhDw4) {
		this.yhDw4 = yhDw4;
	}

	public String getYhDw5() {
		return yhDw5;
	}

	public void setYhDw5(String yhDw5) {
		this.yhDw5 = yhDw5;
	}

	public String getYhDwDate1() {
		return yhDwDate1;
	}

	public void setYhDwDate1(String yhDwDate1) {
		this.yhDwDate1 = yhDwDate1;
	}

	public String getYhDwDate2() {
		return yhDwDate2;
	}

	public void setYhDwDate2(String yhDwDate2) {
		this.yhDwDate2 = yhDwDate2;
	}

	public String getYhDwDate3() {
		return yhDwDate3;
	}

	public void setYhDwDate3(String yhDwDate3) {
		this.yhDwDate3 = yhDwDate3;
	}

	public String getYhDwDate4() {
		return yhDwDate4;
	}

	public void setYhDwDate4(String yhDwDate4) {
		this.yhDwDate4 = yhDwDate4;
	}

	public String getYhDwDate5() {
		return yhDwDate5;
	}

	public void setYhDwDate5(String yhDwDate5) {
		this.yhDwDate5 = yhDwDate5;
	}

	public String getYhGpCode() {
		return yhGpCode;
	}

	public void setYhGpCode(String yhGpCode) {
		this.yhGpCode = yhGpCode;
	}

	public String getYhGpDate() {
		return yhGpDate;
	}

	public void setYhGpDate(String yhGpDate) {
		this.yhGpDate = yhGpDate;
	}

	public String getYhGpType() {
		return yhGpType;
	}

	public void setYhGpType(String yhGpType) {
		this.yhGpType = yhGpType;
	}

	public String getYhGpUnit() {
		return yhGpUnit;
	}

	public void setYhGpUnit(String yhGpUnit) {
		this.yhGpUnit = yhGpUnit;
	}

	public String getYhXhDate() {
		return yhXhDate;
	}

	public void setYhXhDate(String yhXhDate) {
		this.yhXhDate = yhXhDate;
	}

	public String getYhZgPer() {
		return yhZgPer;
	}

	public void setYhZgPer(String yhZgPer) {
		this.yhZgPer = yhZgPer;
	}

	public String getYhZgUnit() {
		return yhZgUnit;
	}

	public void setYhZgUnit(String yhZgUnit) {
		this.yhZgUnit = yhZgUnit;
	}

	public String getYhZgZj() {
		return yhZgZj;
	}

	public void setYhZgZj(String yhZgZj) {
		this.yhZgZj = yhZgZj;
	}

	public String getYhZrUnit() {
		return yhZrUnit;
	}

	public void setYhZrUnit(String yhZrUnit) {
		this.yhZrUnit = yhZrUnit;
	}

	public String getIsSubmit() {
		return isSubmit;
	}

	public void setIsSubmit(String isSubmit) {
		this.isSubmit = isSubmit;
	}

	public String getYhWcDate() {
		return yhWcDate;
	}

	public void setYhWcDate(String yhWcDate) {
		this.yhWcDate = yhWcDate;
	}

	public List getYhTypeList() {
		return yhTypeList;
	}

	public void setYhTypeList(List yhTypeList) {
		this.yhTypeList = yhTypeList;
	}

	public String getCorpId() {
		return corpId;
	}

	public void setCorpId(String corpId) {
		this.corpId = corpId;
	}

	public String getYhType() {
		return yhType;
	}

	public void setYhType(String yhType) {
		this.yhType = yhType;
	}

	public List getCorpList() {
		return corpList;
	}

	public void setCorpList(List corpList) {
		this.corpList = corpList;
	}

	public String getYhAdds() {
		return yhAdds;
	}

	public void setYhAdds(String yhAdds) {
		this.yhAdds = yhAdds;
	}

	public String getYhBwei() {
		return yhBwei;
	}

	public void setYhBwei(String yhBwei) {
		this.yhBwei = yhBwei;
	}

	public String getYhFxTime() {
		return yhFxTime;
	}

	public void setYhFxTime(String yhFxTime) {
		this.yhFxTime = yhFxTime;
	}

	public String getYhJkcs() {
		return yhJkcs;
	}

	public void setYhJkcs(String yhJkcs) {
		this.yhJkcs = yhJkcs;
	}

	public String getYhXcyy() {
		return yhXcyy;
	}

	public void setYhXcyy(String yhXcyy) {
		this.yhXcyy = yhXcyy;
	}

	public String getYhYxfw() {
		return yhYxfw;
	}

	public void setYhYxfw(String yhYxfw) {
		this.yhYxfw = yhYxfw;
	}

	public String getYhZgType() {
		return yhZgType;
	}

	public void setYhZgType(String yhZgType) {
		this.yhZgType = yhZgType;
	}

	public String getYhZgZrr() {
		return yhZgZrr;
	}

	public void setYhZgZrr(String yhZgZrr) {
		this.yhZgZrr = yhZgZrr;
	}

	public String getYhZrrTel() {
		return yhZrrTel;
	}

	public void setYhZrrTel(String yhZrrTel) {
		this.yhZrrTel = yhZrrTel;
	}

	public String getYhZgTime() {
		return yhZgTime;
	}

	public void setYhZgTime(String yhZgTime) {
		this.yhZgTime = yhZgTime;
	}

}
